//////////////////////////////////////////////////////////////////////////
//
// This file is a part of APNS provider project.
// Copyright (c) Vladimir Gumenuk, 2013-2014.
//
// PROJECT:         APNS provider
// FILE:            SimpleThread.h: interface for the CSimpleThread class.
// AUTHOR:          Vladimir Gumenuk
// DATE:            25-Dec-2013
// MODIFICATIONS:
//
//////////////////////////////////////////////////////////////////////////

#if !defined(AFX_SIMPLETHREAD_H__58212012_EE48_469E_BF6E_3284818DD084__INCLUDED_)
#define AFX_SIMPLETHREAD_H__58212012_EE48_469E_BF6E_3284818DD084__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

class CSimpleThread
{
public:
    CSimpleThread();
    virtual ~CSimpleThread();

    HRESULT StartThread();
    void    StopThread();
    bool    IsRunning();
    BOOL    PostMessage( UINT iMsg, WPARAM wParam = 0, LPARAM lParam = 0 );

protected:
    // overrides
    virtual bool  InitInstance() { return true; }
    virtual void  ExitInstance() { ; }
    virtual void  Run();
    
    // access
    inline const HANDLE GetThreadHandle() const { return m_hThread; }
    inline DWORD        GetThreadID() const { return m_dwThreadID; }

private:
    static DWORD __stdcall StaticThreadProc( void *pParam );
    void SetRunning( bool bRun );
    void SetThreadEvent( bool bResult );

    bool                m_bIsRunning;
    HANDLE              m_hThread;
    DWORD               m_dwThreadID;
    HANDLE              m_hWaitEvent;
    bool                m_bThreadResult;
    CComCriticalSection m_runCS;
};

#endif // !defined(AFX_SIMPLETHREAD_H__58212012_EE48_469E_BF6E_3284818DD084__INCLUDED_)
